//
//  GreenButton.m
//  SXH
//
//  Created by Ryan on 16/6/15.
//  Copyright © 2016年 lyss. All rights reserved.
//

#import "GreenButton.h"

@implementation GreenButton

- (void)drawRect:(CGRect)rect
{
    [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self setBackgroundImage:[self imageWithColor:GreenColor] forState:UIControlStateNormal];
    self.layer.cornerRadius = 4;
    self.layer.masksToBounds = YES;
    
}

- (void)setTitle:(NSString *)title
{
    _title = title;
    [self setTitle:title forState:UIControlStateNormal];
}

- (UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}
@end
